local xinjiangyugao = fk.CreateSkill{
    name = "rmt__xinjiangyugao",
}
Fk:loadTranslationTable{
    ["rmt__xinjiangyugao"] = "新将预告",
    [":rmt__xinjiangyugao"] = "准备阶段，你可以展示五个“佚名”的武将并秘密选择其中一个，声明其至多三个特征并摸等量张牌。然后其他角色同时猜测你声明的武将，你交给猜对者一张手牌，猜错者失去1点体力。若均猜对，你获得该武将的技能。"..
    "<br>（特征包括：神人，过牌，弱将，辅助，输出，涩涩）",
    ["#rmt__xinjiangyugao1"] = "神人",
    ["#rmt__xinjiangyugao2"] = "过牌",
    ["#rmt__xinjiangyugao3"] = "弱势",
    ["#rmt__xinjiangyugao4"] = "辅助",
    ["#rmt__xinjiangyugao5"] = "输出",
    ["#rmt__xinjiangyugao6"] = "涩涩",
    ["@&rmt__xinjiangyugao-phase"] = "新将预告",
    ["#rmt__xinjiangyugao_general"] = "新将预告：秘密选择一张武将牌",
    ["#rmt__xinjiangyugao_choice"] = "新将预告：请你声明 %arg 的至多三个特征并摸等量张牌",
    ["#rmt__xinjiangyugao_gengral-log"] = "%from 发动了〖%arg〗，展示了 %arg2",
    ["#rmt__xinjiangyugao_choice-log"] = "%from 声明选择武将有以下特征：%arg",
    ["#rmt__xinjiangyugao-prompt"] = "新将预告：%dest 声明选择武将有以下特征：%arg。请猜测其选择的武将",
    ["#rmt__xinjiangyugao-prompt2"] = "新将预告：%dest没有声明武将特征，请猜测其选择的武将",
    ["#rmt__xinjiangyugao-give"] = "新将预告：%dest 猜对了你选择的武将，交给其一张手牌",
}

xinjiangyugao:addEffect(fk.EventPhaseStart, {
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(xinjiangyugao.name) and target.phase == Player.Start and target == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local record = room:getTag("rmt__xinjiangyugao_recod")
        if record == nil then
            record = {}
            for _, package in pairs(Fk.packages) do
                if package.extensionName == "ym_Al" then
                    for _, general in ipairs(package.generals) do
                        if not Fk.generals[general.name].hidden and not Fk.generals[general.name].total_hidden then
                            table.insert(record, general.name)
                        end
                    end
                end
            end
            room:setTag("rmt__xinjiangyugao_recod", record)
        end
        if #record == 0 then return end
        local generals = table.random(record,5)
        room:setPlayerMark(player,"@&rmt__xinjiangyugao-phase",generals)
        room:sendLog({
            type = "#rmt__xinjiangyugao_gengral-log",
            from = player.id,
            arg = xinjiangyugao.name,
            arg2 = table.concat(table.map(generals,Util.TranslateMapper),"、"),
            toast = true,
        })
        local result = room:askToCustomDialog(player, {
            skill_name = xinjiangyugao.name,
            qml_path = "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml",
            extra_data = {
                generals,
                {"OK"},
                "#rmt__xinjiangyugao_general",
                {},
                1,
                1
            }
        })
        local reply = result
        if result == "" then
            reply = {
                cards = {table.random(generals)}
            }
        end
        if reply and reply.cards and type(reply.cards) == "table" and #reply.cards > 0 then
            local general = reply.cards[1]
            local choices = room:askToChoices(player, {
                choices = {"#rmt__xinjiangyugao1","#rmt__xinjiangyugao2","#rmt__xinjiangyugao3",
                "#rmt__xinjiangyugao4","#rmt__xinjiangyugao5","#rmt__xinjiangyugao6"},
                max_num = 3,
                min_num = 0,
                skill_name = xinjiangyugao.name,
                cancelable = false,
                prompt = "#rmt__xinjiangyugao_choice:::"..general,
            })
            local prompt = "#rmt__xinjiangyugao-prompt2::"..target.id
            if #choices > 0 then
                player:drawCards(#choices,xinjiangyugao.name)
                room:sendLog({
                    type = "#rmt__xinjiangyugao_choice-log",
                    from = player.id,
                    arg = table.concat(table.map(choices,Util.TranslateMapper),"、"),
                    toast = true,
                })
                prompt = "#rmt__xinjiangyugao-prompt::"..target.id..":"..table.concat(table.map(choices,Util.TranslateMapper))
            end

            local req = Request:new(room:getOtherPlayers(player), "AskForChoice")
            req.focus_text = xinjiangyugao.name
            req.receive_decode = false
            for _, cp in ipairs(room:getOtherPlayers(player)) do
                req:setData(cp, {generals, generals, xinjiangyugao.name, prompt})
                req:setDefaultReply(cp, table.random(generals))
            end
            req:ask()
            local trueP, falseP = {}, {}
            for _, p in ipairs(room:getOtherPlayers(player)) do
                if req:getResult(p) == general then
                    table.insert(trueP,p)
                else
                    table.insert(falseP,p)
                end
                room:sendLog{
                    type = "#Choice",
                    from = p.id,
                    arg = req:getResult(p),
                    toast = true,
                }
            end
            for _, cp in ipairs(trueP) do
                if not (cp.dead or player:isKongcheng() or cp == player or player.dead) then
                    local card = room:askToCards(player, {
                        max_num = 1,
                        min_num = 1,
                        include_equip = false,
                        skill_name = xinjiangyugao.name,
                        cancelable = false,
                        prompt = "#rmt__xinjiangyugao-give::"..cp.id
                    })
                    room:moveCardTo(card, Card.PlayerHand, cp, fk.ReasonGive, xinjiangyugao.name, nil, false, player.id)
                end
            end
            for _, cp in ipairs(falseP) do
                if not cp.dead then
                    room:loseHp(cp,1,xinjiangyugao.name)
                end
            end
            if #falseP == 0 then
                local skills = Fk.generals[general]:getSkillNameList(true)
                room:handleAddLoseSkills(player,skills)
            end
        end
        room:setPlayerMark(player,"@&rmt__xinjiangyugao-phase",0)
    end,
})

return xinjiangyugao